package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.ArchiveUsagePurpose;
import com.ruoyi.system.mapper.ArchiveUsagePurposeMapper;
import com.ruoyi.system.service.ArchiveUsagePurposeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 档案利用目的统计 Service 实现类
 * 具体实现业务逻辑，事务控制等
 *
 * @author 你的名字
 */
@Service
public class ArchiveUsagePurposeServiceImpl implements ArchiveUsagePurposeService {

    @Autowired
    private ArchiveUsagePurposeMapper purposeMapper;

    @Override
    public List<ArchiveUsagePurpose> selectArchiveUsagePurposeList(ArchiveUsagePurpose purpose) {
        return purposeMapper.selectArchiveUsagePurposeList(purpose);
    }

    @Override
    public ArchiveUsagePurpose selectArchiveUsagePurposeById(Long id) {
        return purposeMapper.selectArchiveUsagePurposeById(id);
    }

    @Override
    public int insertArchiveUsagePurpose(ArchiveUsagePurpose purpose) {
        return purposeMapper.insertArchiveUsagePurpose(purpose);
    }

    @Override
    public int updateArchiveUsagePurpose(ArchiveUsagePurpose purpose) {
        return purposeMapper.updateArchiveUsagePurpose(purpose);
    }

    @Override
    public int deleteArchiveUsagePurposeById(Long id) {
        return purposeMapper.deleteArchiveUsagePurposeById(id);
    }

    @Override
    public int deleteArchiveUsagePurposeByIds(Long[] ids) {
        return purposeMapper.deleteArchiveUsagePurposeByIds(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchSaveArchiveUsagePurpose(List<ArchiveUsagePurpose> list) {
        // 1. 删除所有旧数据
        purposeMapper.deleteAllArchiveUsagePurpose();
        // 2. 批量插入新数据
        return purposeMapper.batchInsertArchiveUsagePurpose(list);
    }
}